/***************************************************************************
 *   Copyright (C) 2009 by Philipp Müller                                  *
 *   philipp.mueller@gmx.de                                                *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA          *
 ***************************************************************************/

#include "qtvomp.h"

#include "settings.h"

Settings::Settings( MainWindow* mainWindow )
{
    m_mainWindow = mainWindow;
}


void Settings::loadSettings()
{
    //Aspect ratio
    m_aspectRatio = m_mainWindow->vdr()->loadConfig( "General", "AspectRatio" );

    qDebug() << "WidgetOptions::loadOptions: aspectRatio is now: " << m_aspectRatio;

    aspectRatio = Phonon::VideoWidget::AspectRatioAuto; //Default

    if ( m_aspectRatio == "Widget" )
    {
        aspectRatio = Phonon::VideoWidget::AspectRatioWidget;
    }
    if ( m_aspectRatio == "4_3" )
    {
        aspectRatio = Phonon::VideoWidget::AspectRatio4_3;
    }
    if ( m_aspectRatio == "16_9" )
    {
        aspectRatio = Phonon::VideoWidget::AspectRatio16_9;
    }

    //Scale mode
    m_scaleMode = m_mainWindow->vdr()->loadConfig( "General", "ScaleMode" );

    qDebug() << "WidgetOptions::loadOptions: scaleMode is now: " << m_scaleMode;

    scaleMode = Phonon::VideoWidget::FitInView; //Default

    if ( m_scaleMode == "ScaleAndCrop")
    {
        scaleMode = Phonon::VideoWidget::ScaleAndCrop;
    }
}


void Settings::saveAspectRatio()
{
    QString text;
    switch ( aspectRatio )
    {
        case Phonon::VideoWidget::AspectRatioAuto:
            text = "Auto";
            break;
        case Phonon::VideoWidget::AspectRatioWidget:
            text = "Widget";
            break;
        case Phonon::VideoWidget::AspectRatio4_3:
            text = "4_3";
            break;
        case Phonon::VideoWidget::AspectRatio16_9:
            text = "16_9";
            break;
        default:
            text = "Auto";
    }
    m_mainWindow->vdr()->saveConfig( "General", "AspectRatio", text );
}


void Settings::saveScaleMode()
{
    QString text;
    switch ( scaleMode )
    {
        case Phonon::VideoWidget::FitInView:
            text = "FitInView";
            break;
        case Phonon::VideoWidget::ScaleAndCrop:
            text = "ScaleAndCrop";
            break;
        default:
            text = "FitInView";
    }
    m_mainWindow->vdr()->saveConfig( "General", "ScaleMode", text );
}
